﻿using System;
using System.Collections.Generic;
using System.Management;
using System.Windows.Forms;
using System.Linq;

namespace BatteryNotify
{
	public partial class WindowsTemp : Form
	{
		public WindowsTemp()
		{
			InitializeComponent();
		}

		public void ShowTemperature()
		{
			List<Temperature> abc = GetTemperatures();
			foreach( Temperature item in abc)
			{
				rtbWinTemp.AppendText(item.InstanceName.ToString() + "; " + item.CurrentValue.ToString() + "\n");
			}
		}

		public List<Temperature> GetTemperatures()
		{
			List<Temperature> result = new List<Temperature>();
			ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature");
			foreach (ManagementObject obj in searcher.Get())
			{
				Double temp = Convert.ToDouble(obj["CurrentTemperature"].ToString());
				temp = (temp - 2732) / 10.0;
				result.Add(new Temperature { CurrentValue = temp, InstanceName = obj["InstanceName"].ToString() });
			}
			return result;
		}
	}

	public class Temperature
	{
		public double CurrentValue { get; set; }
		public string InstanceName { get; set; }
	}
}
